import subprocess
from util.poses.pose_utils import gen_poses
import argparse
import os
import requests
arg_parser=argparse.ArgumentParser()
arg_parser.add_argument("--match_type",type=str,default="exhaustive_matcher")#只有exhaustive_matcher和sequential_matcher这两种，前一种表示选择全局最优的图片组合实现特征点匹配，后一种则要求图片按照合适的顺序排列
arg_parser.add_argument("scenedir",type=str)
args=arg_parser.parse_args()
assert args.match_type in ("exhaustive_matcher","sequential_matcher"),"match type error"

if __name__=="__main__":
      success,hwf=gen_poses(args.scenedir,args.match_type)
      # 切换到目标文件夹所在的父级目录
      subprocess.run(['pwd'])
      os.chdir(args.scenedir)
      subprocess.run(['pwd'])
      # subprocess.run(['zip','-q','-o',os.path.join(args.scenedir,args.scenedir.split("/")[-1]+".zip"), os.path.join(args.scenedir,"images","*"),os.path.join(args.scenedir,"poses_bounds.npy")], check=True)
      print(hwf)
      subprocess.run(['zip','-q','-r','-o',args.scenedir.split("/")[-1]+".zip", "images","poses_bounds.npy"], check=True)
      subprocess.run(['cp', '-r', args.scenedir+"/out.ply", "/home/carbon/IdeaProjects/carck/src/main/resources/static/"+args.scenedir.split("/")[-1]+".ply"], check=True)
      #请求服务器
      serverAddr="localhost"
      serverPort="6006"
      data = {'scene_name': args.scenedir.split("/")[-1],'width': int(hwf[1]),'height': int(hwf[0])}
      response = requests.post("http://"+serverAddr+":"+serverPort+"/uploadNerfData", data=data, files={'file': open(os.path.join(args.scenedir,args.scenedir.split("/")[-1]+".zip"), 'rb')})


